//
//  XYFeedbackViewController.m
//  NemoSDKDemo
//
//  Created by 高超 on 2020/7/29.
//  Copyright © 2020 JackYang. All rights reserved.
//

#import "XYFeedbackViewController.h"
#import "UIColor+XYColor.h"

@interface XYFeedbackViewController ()<UITextViewDelegate>
@property (weak, nonatomic) IBOutlet UITextView *feedbackTV;
@property (weak, nonatomic) IBOutlet UIButton *sendBtn;

@end

@implementation XYFeedbackViewController

- (void)viewDidLoad {
    [super viewDidLoad];
     
    self.navigationItem.title = @"快速反馈";
    [self _setupSubView];
}

- (BOOL)shouldAutorotate{
    //不允许转屏
    return NO;
}

#pragma mark private function
- (void)_setupSubView {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(20, 0, 42, 40)];
    view.backgroundColor = [UIColor clearColor];
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"navigation_back"] forState:UIControlStateNormal];
    button.frame = CGRectMake(5, 0, 42, 35);
    [button addTarget:self action:@selector(_goBack) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];
    button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc]initWithCustomView:view];
    self.navigationItem.leftBarButtonItem = backButtonItem;
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    
    self.feedbackTV.layer.cornerRadius = 10.f;
    self.sendBtn.layer.cornerRadius = self.sendBtn.bounds.size.height/2.f;
}

- (void)_goBack {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark IBAction
- (IBAction)sendAction:(id)sender {
    [XYHUDManager showLoading];
    [[XYSDKManager sharedInstance] sendFeedbackLogWithComments:_feedbackTV.text];
}

- (IBAction)tapViewAction:(id)sender {
    [self.feedbackTV resignFirstResponder];
}

#pragma mark UITextViewDelegate
- (void)textViewDidChange:(UITextView *)textView {
    if (textView.text.length) {
        self.sendBtn.enabled = YES;
        self.sendBtn.alpha = 1;
    }else {
        self.sendBtn.enabled = NO;
        self.sendBtn.alpha = 0.4;
    }
}



@end
